package com.cloudweb.oa.module.desktop;

import cn.js.fan.db.ResultIterator;
import cn.js.fan.db.ResultRecord;
import cn.js.fan.db.SQLFilter;
import com.cloudweb.oa.api.IDesktopCard;
import com.cloudwebsoft.framework.db.JdbcTemplate;
import com.redmoon.oa.flow.WorkflowDb;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

public class DesktopCardFlowDoing implements IDesktopCard {
    DesktopCard desktopCard;

    public DesktopCardFlowDoing(DesktopCard desktopCard) {
        this.desktopCard = desktopCard;
    }

    @Override
    public String getTitle() {
        return desktopCard.getTitle();
    }

    @Override
    public int getStartVal() {
        return 0;
    }

    @Override
    public int getEndVal(HttpServletRequest request) {
        WorkflowDb wf = new WorkflowDb();
        String sql = wf.getSqlDoing(request);
        JdbcTemplate jt = new JdbcTemplate();
        try {
            ResultIterator ri = jt.executeQuery(SQLFilter.getCountSql(sql));
            if (ri.hasNext()) {
                ResultRecord rr = ri.next();
                return rr.getInt(1);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return 0;
    }

    @Override
    public boolean isLink() {
        return desktopCard.isLink();
    }

    @Override
    public String getUrl() {
        return "flow/flow_list.jsp?displayMode=1";
    }

    @Override
    public String getUnit() {
        return desktopCard.getUnit();
    }

    @Override
    public String getBgColor() {
        return desktopCard.getBgColor();
    }

    @Override
    public String getIcon() {
        return desktopCard.getIcon();
    }
}
